using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using TVDesigner.GUI.Elements;

namespace TVDesigner.GUI.Controls.Toolbox
{
    public class ToolboxButton : System.Windows.Forms.ToolStripButton
    {
        public static int toolboxCount = 0;

        private DesignPanel _DesginPanel;
        //private bool _IsDragging;
        private EToolboxType _ToolboxType;

        public ToolboxButton(DesignPanel designPanel, EToolboxType toolboxType)
        {
            _DesginPanel = designPanel;
            _ToolboxType = toolboxType;

            this.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.Name = "toolStripButton" + toolboxCount;
            this.Size = new System.Drawing.Size(29, 20);
            this.Text = "toolStripButton" + toolboxCount;
            this.ToolTipText = toolboxType.ToString();

            this.Click += new System.EventHandler(ToolboxButton_MouseClick);
            toolboxCount++;

            switch (_ToolboxType)
            {
                case EToolboxType.Button:
                    this.Image = TVDesigner.GUI.Properties.Resources.button;
                    break;
                case EToolboxType.Text:
                    this.Image = TVDesigner.GUI.Properties.Resources.label;
                    break;
                case EToolboxType.Image:
                    this.Image = TVDesigner.GUI.Properties.Resources.hImage1;
                    break;
                case EToolboxType.Remove:
                    this.Image = TVDesigner.GUI.Properties.Resources.remove;
                    break;
                case EToolboxType.ScreenResize:
                    this.Image = TVDesigner.GUI.Properties.Resources.screen;
                    break;
                case EToolboxType.Table:
                    this.Image = TVDesigner.GUI.Properties.Resources.table;
                    break;
                default:
                    break;
            }
        }

        protected void ToolboxButton_MouseClick(object sender, EventArgs e)
        {
            if (_ToolboxType == EToolboxType.Remove)
            {
                _DesginPanel.RemoveSelectedElement();
            }
            else
            {
                Element element = null;
                if (_ToolboxType == EToolboxType.Button)
                {
                    element = new ButtonElement();
                }
                else if (_ToolboxType == EToolboxType.Image)
                {
                    element = new PictureElement();
                }
                else if (_ToolboxType == EToolboxType.Text)
                {
                    element = new TextElement();
                }
                else if (_ToolboxType == EToolboxType.ScreenResize)
                {
                    element = new ScreenResizeElement();
                }

                element.Location = new Point(10, 10);
                _DesginPanel.AddNewElement(element, true);
            }
        }
    }
}
